package com.opeartion.controller;


import com.opeartion.feign.StoreFeign;
import com.opeartion.pojo.CheckStatus;
import com.opeartion.pojo.Store;
import com.wink.entity.Result;
import com.wink.entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/store")
public class StoreController {

    @Autowired
    private StoreFeign storeFeign;


    @GetMapping("/list")
    public Result getAll() {
        try {
            List<Store> allStore = storeFeign.getAllStore();
            return new Result(true, StatusCode.ACCESSERROR, "返回成功", allStore);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "返回失败");
        }
    }


    @GetMapping("/findStore")
    public Result findStore(@RequestParam("storeld") String storeld) {
        System.out.println(storeld + "---------------------------------");
        try {
            List<Store> allStore = storeFeign.findStore(storeld);
            return new Result(true, StatusCode.ACCESSERROR, "返回成功", allStore);
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "返回失败");
        }

    }

    @GetMapping("/findCategotry")
    public Result findCategotry(@RequestParam("name") String name) {
        System.out.println(name);
        try {
            List<Store> allStore = storeFeign.findCategotry(name);
            return new Result(true, StatusCode.ACCESSERROR, "返回成功", allStore);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "返回失败");
        }
    }

    @PostMapping("/updateStoreId")
    public Result UpdateStoreId(@RequestParam("status") Integer status, @RequestParam("id") Integer id) {
        try {
            System.out.println(status + "" + id);
            storeFeign.UpdateStoreId(status, id);
            return new Result(true, StatusCode.ACCESSERROR, "返回成功");
        } catch (Exception e) {
            return new Result(false, StatusCode.ERROR, "返回失败");
        }
    }

    @GetMapping("/checkStatus")
    public Result checkStatus() {
        try {
            return new Result(true, StatusCode.ACCESSERROR, "返回成功",storeFeign.checkStatus());
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "返回失败");
        }
    }
    @PostMapping("/findStatus")
    public Result findStatus(CheckStatus checkStatus) {
        try {
            System.out.println(checkStatus);
            return new Result(true, StatusCode.ACCESSERROR, "返回成功", storeFeign.findStatus(checkStatus));
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "返回失败");
        }
    }

}
